package com.example.temp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.temp.entity.AssetInformation;
import com.example.temp.entity.AssetLend;
import com.example.temp.entity.AssetSubscribe;
import com.example.temp.mapper.AssetMaintainMapper;
import com.example.temp.mapper.AssetSubscribeMapper;
import com.example.temp.utils.RandomNumberUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class AssetSubscribeService extends ServiceImpl<AssetSubscribeMapper, AssetSubscribe> {

//    @Autowired
    private AssetMaintainMapper assetMaintainMapper;

    @Autowired
    private AssetInformationService assetInformationService;

    /**
     * 保存添加的资产申购信息
     *
     * @param assetSubscribe
     * @return
     */
    public boolean saveAssetSubscribe(AssetSubscribe assetSubscribe) {
        assetSubscribe.setAudit("否");
        return saveOrUpdate(assetSubscribe);
    }

    /**
     * 审核：同意购买
     *
     * @param assetSubscribe
     * @return
     */
    public boolean autiSubscribe(AssetSubscribe assetSubscribe) {

        AssetInformation asset = new AssetInformation();
        String assetNum = assetInformationService.generateUniqueSerialNumber();
        asset.setAssetNumber(assetNum);
        asset.setName(assetSubscribe.getName());
        asset.setType(assetSubscribe.getType());
        asset.setPrice(assetSubscribe.getPrice());
        asset.setAddtime(assetSubscribe.getAddtime());
        asset.setPicture(assetSubscribe.getPicture());
        asset.setAssetState("正常");


        assetSubscribe.setAudit("是");
        assetSubscribe.setAssetNumber(assetNum);

        return assetInformationService.saveOrUpdate(asset) && saveOrUpdate(assetSubscribe);
    }


}
